<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img{
            display: inline-block;
            width: 256px;
            height: 192px;
            /* 隐藏Firefox alt 文字 */
            color:transparent;
            position: relative;
            overflow: hidden;
        }
        img:not([src]){
            /* 隐藏Chrome alt 文字以及银色边框 */
            visibility: hidden;
        }
        img::before{
            /* 淡蓝色占位背景  */
            content: '';
            position: absolute;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #f0f3f9;
            visibility: visible;
        }

        img::after{
            content: attr(alt);
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            line-height: 30px;
            background-color: rgba(0, 0, 0,.5);
            color: white;
            font-size: 14px;
            transform: translateY(100%);
            transition: transform .2s;
            visibility: visible;
        }
        img:hover::after{
            transform: translateY(0);
        }

    </style>
</head>
<body>
    <img alt="美女深思图" data-src="1.jpeg">
    <p><button>设置src属性显示图片</button></p>
</body>
</html>
<script>
    let element = document.querySelector('button')
        eleImg = document.querySelector('img')
    if(element && eleImg){
        let initValueButton = element.innerHTML
        let srcImage = eleImg.getAttribute('data-src')
        eleImg.removeAttribute('data-src')
        element.addEventListener('click',function(){
            if(this.innerHTML === initValueButton){
                this.innerHTML = '移除src属性'
                eleImg.setAttribute('src',srcImage)
            }else{
                this.innerHTML = initValueButton
                eleImg.removeAttribute('src')
            }
        })
    }
</script>